﻿#include "kbeapp.h"
#include "helper/log.h"

using namespace xpy;

KBEThread::KBEThread(KBEApp* app)
{
	m_app = app;
}

KBEThread::~KBEThread()
{
}

void KBEThread::run()
{
	logger::info("KBEThread::run()");
	over = false;

	try
	{
		m_app->process();
	}
	catch (std::exception &ex)
	{
		logger::error("Error:", ex.what());
	}

	over = true;
	logger::info("KBEThread::end()");
}

KBEApp::KBEApp(KBEConfig *config)
{
	m_cfg = config;
	initialize();
}

KBEApp::~KBEApp()
{
}

bool KBEApp::initialize()
{
	threadUpdateHZ = m_cfg->threadUpdateHZ;
	threadUpdatePeriod = 1000.0 / threadUpdateHZ;

	kbethread = new KBEThread(this);

	_t = new std::thread([&]() {kbethread->run(); });
	_t->detach();
	
	return true;
}

void KBEApp::process()
{

}

void KBEApp::initNetwork()
{

}
